home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / n_b_v203.zip / TINPUT.DMO < prev    next >
Text File  |  1996-07-04  |  11KB  |  269 lines

  1. $if 0
  2.     ┌──────────────────────────╖                        PowerBASIC v3.20
  3.  ┌──┤          DASoft          ╟──────────────────────┬──────────────────╖
  4.  │  ├──────────────────────────╢    Copyright 1995    │ DATE: 1995-10-01 ╟─╖
  5.  │  │ FILE NAME   TINPUT  .DMO ║          by          ╘════════════════─ ║ ║
  6.  │  │                          ║  Don Schullian, Jr.                     ║ ║
  7.  │  ╘══════════════════════════╝                                         ║ ║
  8.  │ A license is hereby granted to the holder to use this source code in  ║ ║
  9.  │ any program, commercial or otherwise,  without receiving the express  ║ ║
  10.  │ permission of the copyright holder and without paying any royalties,  ║ ║
  11.  │ as long as this code is not distributed in any compilable format.     ║ ║
  12.  │  IE: source code files, PowerBASIC Unit files, and printed listings   ║ ║
  13.  ╘═╤═════════════════════════════════════════════════════════════════════╝ ║
  14.    │                ....................................                   ║
  15.    ╘═══════════════════════════════════════════════════════════════════════╝
  16. $endif
  17.  
  18. '.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°.°
  19. ' ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° ° °
  20.  
  21. $INCLUDE "DAS-NB01.INC"
  22. $INCLUDE "DAS-NB02.INC"
  23. $INCLUDE "DAS-NBT1.INC"
  24. $INCLUDE "DAS-NBT2.INC"
  25. $INCLUDE "DMO\TINPUT2.INC"
  26.  
  27. SCREEN 0,,0,0
  28. COLOR 0,7,7
  29. CLS
  30.  
  31. DIM tCC AS SHARED CountryCodeTYPE
  32. LSET tCC = fGetCountry$(0)
  33. SetDateFormat tCC.DateFormat, tCC.DateSep
  34. SetInsertMsg " INSERT .ON ", " INSERT (OFF", 24, 69
  35. HelpLineSetup 24, 14, 52, 32
  36. ON TIMER (1) GOSUB CLOCK
  37.  
  38. GOSUB InputScreen
  39. GOSUB GatherData
  40. PrintPrompts D$(), F$(), Prompt$()
  41. S$ = CHR$(4,6,11,14)
  42. StartFld% = 6
  43.  
  44. IF fTinput2%( D$(), F$(), S$, H$(), StartFld% ) = %F10_key THEN
  45.   ' STORE NEW DATA
  46. END IF
  47.  
  48. BYEBYE:
  49.   COLOR 7, 0, 0
  50.   LOCATE 1,1,0
  51.   CLS
  52.   END
  53.  
  54. ' ──────────────────────────────────────────────────────────────────────────
  55. ' ──────────  local stuff
  56. ' ──────────────────────────────────────────────────────────────────────────
  57.  
  58. ' Generally, in a real program, I split the printing of prompts from the
  59. ' printing of data for 2 reasons:
  60. '    1) the prompts only have to be done once (usually)
  61. '    2) the one sub can serve for all the input screens
  62. ' As it appears here it also formats and displays the data. In a different
  63. ' format a similar sub could be used to check the data for range, load
  64. ' required fields with default values, etc. The .Just member of TinputTYPE
  65. ' comes in handy for these tasks.
  66. ' MURPHY'S LAW 1313.2
  67. '   Users will always try to input data in the wrong format!
  68.  
  69. SUB PrintPrompts( SEG D$(), SEG F$(), SEG Prompt$() ) LOCAL PUBLIC
  70.   LOCAL C?, Dyte??, L%, Last%, P$, X%
  71.  
  72.   DIM tINP AS TinputTYPE
  73.   Last% = UBOUND( Prompt$(1) )
  74.  
  75.   FOR X% = 1 TO Last%
  76.     LSET tINP = F$(X%)
  77.     Mask$     = MID$( F$(X%), 9 )
  78.     L%        = LEN( Prompt$(X%) )
  79.     IF L% > 0 THEN
  80.       C? = tINP.Col - L% - 1
  81.       Tprint tINP.Row, C?, Prompt$(X%), 120
  82.     END IF
  83.     IF ( D$(X%) = "" ) AND ( tINP.MustBe > 0 ) THEN
  84.         P$ = STRING$( tINP.Cols, 95 )
  85.       ELSE
  86.         P$ = ""
  87.     END IF
  88.     SELECT CASE UCASE$( tINP.Style )
  89.       CASE "A", "M", "P"
  90.         IF D$(X%) > "" THEN P$ = D$(X%)
  91.       CASE "B"
  92.         IF D$(X%) <> "" THEN
  93.             TprintTEXT tINP.Row, tINP.Col, tINP.Misc, tINP.Cols, D$(X%), 1, 0, 0, 113
  94.           ELSE
  95.             TboxFILL tINP.Row, tINP.Col, tINP.Misc, tINP.Cols, 95, 113
  96.         END IF
  97.         ITERATE
  98.       CASE "D"
  99.         Dyte?? = fDate2Days??( D$(X%) )
  100.         IF ( Dyte?? = 0 ) AND ( tINP.MustBe > 0 ) THEN Dyte?? = fSYS2Days??
  101.         IF tINP.Cols = 10 THEN
  102.             P$ = fDAYS2DATE$( Dyte?? )
  103.           ELSE
  104.             P$ = fDAYS2DATE8$( Dyte?? )
  105.         END IF
  106.         IF Mask$ <> "" THEN
  107.           C? = ( Dyte?? MOD 7 ) + 1
  108.           P$ = fGetPiece$( Mask$, 124, C? ) + P$
  109.         END IF
  110.       CASE "H"
  111.         IF D$(X%) <> "" THEN P$ = fASCii2Hex$( D$(X%) )
  112.       CASE "N"
  113.         P$ = USING$( Mask$, VAL( D$(X%) ) )
  114.       CASE "Q"
  115.         IF D$(X%) <> "" THEN P$ = fQueryPrint$( 0, 0, 0, Mask$, D$(X%) )
  116.       CASE "T"
  117.         Tyme& = fTime2LongCk&( D$(X%) )
  118.         IF ( Tyme& = 0 ) AND ( tINP.MustBe > 0 ) THEN Tyme& = fSysT2long&
  119.         IF tINP.Cols <> 9 THEN
  120.             P$ = fLONG2Time$( Tyme& )
  121.           ELSE
  122.             P$ = fLONG2HM$  ( Tyme& )
  123.         END IF
  124.     END SELECT
  125.     TprintCLEAR tINP.Row, tINP.Col, tINP.Cols, P$, 113
  126.   NEXT
  127.  
  128. END SUB
  129.  
  130. ' ──────────────────────────────────────────────────────────────────────────
  131.  
  132. FUNCTION fGetKey% LOCAL PUBLIC     '┌────────────────────────────────────
  133.   LOCAL G%                         '│
  134.                                    '│centralize all incoming key-presses
  135.   DO                               '│
  136.     TIMER ON                       '│start the clock printing
  137.       WHILE NOT INSTAT : WEND      '│rem this line out if used with EVENTs
  138.     TIMER STOP                     '│no need slowing down the program
  139.     G% = CVI(INKEY$ + CHR$(0))     '│read next key press
  140.     SELECT CASE G%                 '│
  141.       CASE 124 : G% = 0            '│ block the pipe "|"
  142.     END SELECT                     '│ do whatever else you want here!
  143.   LOOP UNTIL G% <> 0               '│
  144.                                    '│
  145.   FUNCTION = G%                    '│ RETURN VALUE
  146.                                    '│
  147. END FUNCTION                       '└────────────────────────────────────
  148.  
  149. ' ──────────────────────────────────────────────────────────────────────────
  150.  
  151. FUNCTION fJustify$ ( BYVAL V$, BYVAL L%, BYVAL Which% ) LOCAL PUBLIC
  152.  
  153.   SELECT CASE Which%
  154.     CASE 01   : V$ = fRemoveDBLspc$( V$ )
  155.                 V$ = fLRtrim$( V$ )
  156.     CASE 02   : V$ = fLRtrim$    ( V$ )
  157.     CASE 03   : V$ = fJustLeft$  ( V$, L%, 32 )
  158.     CASE 04   : V$ = fJustCenter$( V$, L%, 32 )
  159.     CASE 05   : V$ = fJustRight$ ( V$, L%, 32 )
  160.     CASE 06   : V$ = fJustRight$ ( V$, L%, 48 )   ' PAD LEFT W/ 0s
  161.   END SELECT
  162.   FUNCTION = V$
  163.  
  164. END FUNCTION
  165.  
  166. '───────────────────────────────────────────────────────────────────────────
  167. '───── SIMULATED INPUT SCREEN PRINTER
  168. '───────────────────────────────────────────────────────────────────────────
  169.  
  170. INPUTSCREEN:
  171.   ' notice how you can use a 1 row box to make a message box
  172.   MakeTBox  1,  1, 1, 11, 0, 32, 51, 120, 2, "MAIN MENU"
  173.   MakeTBox  1, 14, 1, 52, 0, 31, 51, 120, 2, "EDITING CUSTOMER RECORDS"
  174.   MakeTBox  1, 68, 1, 12, 0, 32, 51, 120, 2, TIME$
  175.   MakeTBox 24,  1, 1, 11, 0, 32, 51, 120, 2, "F-1  HELP"
  176.   MakeTBox 24, 14, 1, 52, 0, 32, 51, 120, 2, "PRESS ANY KEY TO CONTINUE"
  177.   MakeTBox 24, 68, 1, 12, 0, 32, 51, 120, 2, fSYSdate$
  178. RETURN
  179.  
  180. '───────────────────────────────────────────────────────────────────────────
  181. '───── SIMULATED DATA GATHERING ROUTINE
  182. '───────────────────────────────────────────────────────────────────────────
  183.  
  184. GATHERDATA:
  185.   ' Under real conditions this data would be either read from a file or,
  186.   ' at least, packed as a string to start with to make reading it much less
  187.   ' arduous. ie: F$(5) = CHR$(81,07,69,06,01,0,0,0) + "NMF|N/D....."
  188.   ' Also, the prompts would be stored and loaded separately. I use this
  189.   ' style as it is easier to match prompts with field data.
  190.  
  191.   RESTORE TESTINPUT
  192.   READ Last%
  193.   DIM F$( Last% ), Prompt$( Last% ), D$( Last% ), H$( Last% )
  194.   FOR X% = 1 TO Last%
  195.     READ Prompt$(X%)
  196.     READ F$(X%)
  197.     FOR Y% = 1 TO 7
  198.       READ D? : F$(X%) = F$(X%) + CHR$(D?)
  199.     NEXT
  200.     READ D$   : F$(X%) = F$(X%) + D$
  201.   NEXT
  202.   FOR X% = 1 TO Last%
  203.     READ H$(X%)
  204.   NEXT
  205.  
  206.   D$(01) = "Schullian"         ' This, basically, is how the data should be
  207.   D$(02) = "Donald A."         ' presented to the input routine(s). There is
  208.   D$(03) = "Mr.,PhD"           ' nothing stopping you from storing it on the
  209.   D$(04) = fDays2Date$(27753)  ' disk in a different format. Field 11 could
  210.   D$(05) = "M"                 ' be stored as a single byte then converted to
  211.   D$(06) = "Grammou 33"        ' a number when read in. Field 12 could be
  212.   D$(07) = ""                  ' stored as a single precision number.